home *** CD-ROM | disk | FTP | other *** search
/ Rock County Sheriff's Off…nternet Safety Initative / Rock County Sher.iso / pc / index.files / html5video / flashfox.swf / scripts / frame_1 / DoAction.as
Encoding:
Text File  |  2012-10-23  |  17.1 KB  |  687 lines

  1. function init_vars()
  2. {
  3.    this.is_playing = false;
  4.    this.is_muted = false;
  5.    this.is_seeking = false;
  6.    this.first_hover = false;
  7.    this.duration_minutes = "0";
  8.    this.duration_seconds = "00";
  9.    this.controls_override = false;
  10. }
  11. function fn_resize_poster()
  12. {
  13.    var poster_scale = Math.min(Stage.width / poster_trueWidth,Stage.height / poster_trueHeight);
  14.    with(poster_canvas)
  15.    {
  16.       _width = poster_trueWidth * poster_scale;
  17.       _height = poster_trueHeight * poster_scale;
  18.       _x = (Stage.width - poster_trueWidth * poster_scale) / 2;
  19.       _y = (Stage.height - poster_trueHeight * poster_scale) / 2;
  20.    }
  21. }
  22. function onMetaData(args)
  23. {
  24.    fadeOut(poster_canvas,30);
  25.    video_trueWidth = !_root.width ? args.width || Stage.width : _root.width;
  26.    video_trueHeight = !_root.height ? args.height || Stage.height : _root.height;
  27.    video_duration = args.duration || 0;
  28.    duration_minutes = Math.floor(video_duration / 60);
  29.    duration_seconds = Math.floor(video_duration - duration_minutes * 60);
  30.    duration_seconds = duration_seconds >= 10 ? duration_seconds : "0" + duration_seconds;
  31.    duration_text_holder.duration_text.text = duration_minutes + ":" + duration_seconds;
  32.    duration_text_holder.duration_text.setTextFormat(duration_text_format);
  33.    fn_resize_video();
  34. }
  35. function connect()
  36. {
  37.    this.nc = new NetConnection();
  38.    this.nc.connect(null);
  39.    this.stream = new NetStream(nc);
  40.    this.stream.setBufferTime(10);
  41.    this.video.attachVideo(stream);
  42.    this.video_canvas.attachAudio(stream);
  43.    this.audio = new Sound(video_canvas);
  44.    this.audio.setVolume(100);
  45.    this.stream.onMetaData = onMetaData;
  46. }
  47. function fn_resize_video()
  48. {
  49.    var video_scale = Math.min(Stage.width / video_trueWidth,Stage.height / video_trueHeight);
  50.    with(video)
  51.    {
  52.       _width = video_trueWidth * video_scale;
  53.       _height = video_trueHeight * video_scale;
  54.       _x = (Stage.width - video_trueWidth * video_scale) / 2;
  55.       _y = (Stage.height - video_trueHeight * video_scale) / 2;
  56.    }
  57. }
  58. function fn_draw_controls()
  59. {
  60.    controls_visible = false;
  61.    this.createEmptyMovieClip("controls_bg",20);
  62.    with(controls_bg)
  63.    {
  64.       _alpha = 0;
  65.       beginFill(1709847);
  66.       moveTo(0,Stage.height - 28);
  67.       lineTo(Stage.width,Stage.height - 28);
  68.       lineTo(Stage.width,Stage.height);
  69.       lineTo(0,Stage.height);
  70.       endFill();
  71.    }
  72.    this.createEmptyMovieClip("play_btn",21);
  73.    with(play_btn)
  74.    {
  75.       _alpha = 0;
  76.       _x = 9;
  77.       _y = Stage.height - 20;
  78.       beginFill(16777215);
  79.       moveTo(0,0);
  80.       lineTo(9,6);
  81.       lineTo(0,12);
  82.       endFill();
  83.    }
  84.    this.createEmptyMovieClip("pause_btn",22);
  85.    with(pause_btn)
  86.    {
  87.       _alpha = 0;
  88.       _x = 9;
  89.       _y = Stage.height - 20;
  90.       beginFill(16777215);
  91.       moveTo(0,0);
  92.       lineTo(0,12);
  93.       lineTo(4,12);
  94.       lineTo(4,0);
  95.       endFill();
  96.       beginFill(16777215);
  97.       moveTo(7,0);
  98.       lineTo(7,12);
  99.       lineTo(11,12);
  100.       lineTo(11,0);
  101.       endFill();
  102.    }
  103.    this.createEmptyMovieClip("duration_bar",23);
  104.    with(duration_bar)
  105.    {
  106.       _alpha = 0;
  107.       _x = 32;
  108.       _y = Stage.height - 14;
  109.       lineStyle(8,10263194,80);
  110.       moveTo(0,0);
  111.       lineTo(Stage.width - 98 - BTN_FULL_W,0);
  112.    }
  113.    this.createEmptyMovieClip("progress_bar",24);
  114.    with(progress_bar)
  115.    {
  116.       _alpha = 0;
  117.       _x = 32;
  118.       _y = Stage.height - 14;
  119.       lineStyle(8,13289672,80);
  120.       moveTo(0,0);
  121.       lineTo(7,0);
  122.    }
  123.    this.createEmptyMovieClip("time_slider",25);
  124.    with(time_slider)
  125.    {
  126.       _alpha = 0;
  127.       _x = 28;
  128.       _y = Stage.height - 23;
  129.       lineStyle(2.5,16777215,100);
  130.       beginFill(4671303);
  131.       moveTo(0,5);
  132.       curveTo(0,0,4.5,0);
  133.       curveTo(9,0,9,5);
  134.       lineTo(9,13);
  135.       curveTo(9,18,4.5,18);
  136.       curveTo(0,18,0,13);
  137.       lineTo(0,5);
  138.       endFill();
  139.    }
  140.    this.createEmptyMovieClip("volume_btn",26);
  141.    with(volume_btn)
  142.    {
  143.       _alpha = 0;
  144.       _x = Stage.width - 24 - BTN_FULL_W;
  145.       _y = Stage.height - 22;
  146.       lineStyle(0,16777215,100);
  147.       beginFill(16777215);
  148.       moveTo(0,5);
  149.       lineTo(0,10);
  150.       lineTo(3,10);
  151.       lineTo(8,14);
  152.       lineTo(8,1);
  153.       lineTo(3,5);
  154.       endFill();
  155.    }
  156.    this.createEmptyMovieClip("volume_on_btn",27);
  157.    with(volume_on_btn)
  158.    {
  159.       _alpha = 0;
  160.       _x = Stage.width - 12 - BTN_FULL_W;
  161.       _y = Stage.height - 18;
  162.       lineStyle(3,16777215,100);
  163.       moveTo(0,0);
  164.       curveTo(5,3,0,7);
  165.    }
  166.    this.createEmptyMovieClip("duration_text_holder",28);
  167.    with(duration_text_holder)
  168.    {
  169.       _alpha = 0;
  170.       _x = Stage.width - 56 - BTN_FULL_W;
  171.       _y = Stage.height - 23;
  172.    }
  173.    fullOut._x = fullIn._x = Stage.width - BTN_FULL_W;
  174.    fullOut._y = fullIn._y = Stage.height - BTN_FULL_H;
  175.    fullIn.swapDepths(this.getNextHighestDepth());
  176.    fullOut.swapDepths(this.getNextHighestDepth());
  177.    fullIn._alpha = 0;
  178.    fullOut._alpha = 0;
  179.    duration_text_holder.createTextField("duration_text",29,0,0,60,20);
  180.    duration_text_format = new TextFormat();
  181.    duration_text_format.color = 13421772;
  182.    duration_text_format.font = "Arial";
  183.    duration_text_format.size = "11";
  184.    duration_text_holder.duration_text.text = duration_minutes + ":" + duration_seconds;
  185.    duration_text_holder.duration_text.setTextFormat(duration_text_format);
  186.    this.createEmptyMovieClip("control_canvas",1000);
  187.    control_canvas.buttonMode = false;
  188.    with(control_canvas)
  189.    {
  190.       _alpha = 0;
  191.       beginFill(0);
  192.       moveTo(0,0);
  193.       lineTo(Stage.width,0);
  194.       lineTo(Stage.width,Stage.height);
  195.       lineTo(0,Stage.height);
  196.       endFill();
  197.    }
  198.    control_canvas.onRollOver = function()
  199.    {
  200.       is_seeking = false;
  201.       first_hover = true;
  202.    };
  203.    control_canvas.onRollOut = function()
  204.    {
  205.       controls_hover_timeout = 24;
  206.       is_seeking = false;
  207.    };
  208.    control_canvas.onPress = function()
  209.    {
  210.       if(_root._ymouse >= Stage.height - 28)
  211.       {
  212.          is_seeking = true;
  213.       }
  214.    };
  215.    control_canvas.onMouseMove = function()
  216.    {
  217.       if(is_seeking)
  218.       {
  219.          stream.seek((_root._xmouse - 28) / duration_bar._width * video_duration);
  220.       }
  221.       if(!controls_visible)
  222.       {
  223.          fn_controls_visible(36);
  224.       }
  225.       if(_root._ymouse >= Stage.height - 28)
  226.       {
  227.          controls_hover_timeout = 576;
  228.       }
  229.       else
  230.       {
  231.          controls_hover_timeout = 288;
  232.       }
  233.    };
  234.    control_canvas.onRelease = function()
  235.    {
  236.       if(_root._xmouse <= 28 && _root._ymouse >= Stage.height - 28)
  237.       {
  238.          if(!is_playing)
  239.          {
  240.             fn_play();
  241.          }
  242.          else
  243.          {
  244.             fn_pause();
  245.          }
  246.       }
  247.       else if(_root._xmouse >= Stage.width - 28 - BTN_FULL_W && _root._xmouse <= Stage.width - 4 - BTN_FULL_W && _root._ymouse >= Stage.height - 28)
  248.       {
  249.          if(!is_muted)
  250.          {
  251.             fn_mute();
  252.          }
  253.          else
  254.          {
  255.             fn_unmute();
  256.          }
  257.       }
  258.       else if(fullScreenEnabled && _root._xmouse >= Stage.width - BTN_FULL_W && _root._xmouse <= Stage.width - 4 && _root._ymouse >= Stage.height - BTN_FULL_H)
  259.       {
  260.          if(Stage.displayState == "normal")
  261.          {
  262.             fn_fullscreen();
  263.          }
  264.          else
  265.          {
  266.             fn_fullscreen_off();
  267.          }
  268.       }
  269.       else if(is_seeking)
  270.       {
  271.          stream.seek((_root._xmouse - 28) / duration_bar._width * video_duration);
  272.       }
  273.       is_seeking = false;
  274.    };
  275.    control_canvas.onReleaseOutside = function()
  276.    {
  277.       is_seeking = false;
  278.    };
  279. }
  280. function fn_time()
  281. {
  282.    time_slider._x = duration_bar._width * (video_position / video_duration) + 28;
  283. }
  284. function fn_progress()
  285. {
  286.    progress_bar.lineTo((duration_bar._width - 8) * (video_percent / 100),0);
  287. }
  288. function fadeIn(mc, fadeRate, toAlpha)
  289. {
  290.    toAlpha = toAlpha || 100;
  291.    fadeRate = fadeRate || 20;
  292.    mc.onEnterFrame = null;
  293.    mc.onEnterFrame = function()
  294.    {
  295.       if(this._alpha >= toAlpha)
  296.       {
  297.          this._alpha = toAlpha;
  298.          this.onEnterFrame = null;
  299.       }
  300.       else
  301.       {
  302.          this._alpha += fadeRate;
  303.          this._alpha = Math.min(this._alpha,toAlpha);
  304.       }
  305.    };
  306. }
  307. function fadeOut(mc, fadeRate, toAlpha)
  308. {
  309.    toAlpha = toAlpha || 0;
  310.    fadeRate = fadeRate || 20;
  311.    mc.onEnterFrame = null;
  312.    mc.onEnterFrame = function()
  313.    {
  314.       if(this._alpha <= toAlpha)
  315.       {
  316.          this._alpha = toAlpha;
  317.          this.onEnterFrame = null;
  318.       }
  319.       else
  320.       {
  321.          this._alpha -= Math.max(toAlpha - this._alpha - fadeRate,fadeRate,toAlpha);
  322.       }
  323.    };
  324. }
  325. function fn_controls_visible(fadeRate)
  326. {
  327.    if(!controls_override && controls_locked)
  328.    {
  329.       return undefined;
  330.    }
  331.    controls_visible = true;
  332.    fadeRate = fadeRate || 100;
  333.    fadeIn(controls_bg,fadeRate,70);
  334.    if(is_playing)
  335.    {
  336.       fadeIn(pause_btn,fadeRate);
  337.       play_btn._alpha = 0;
  338.    }
  339.    else
  340.    {
  341.       fadeIn(play_btn,fadeRate);
  342.       pause_btn._alpha = 0;
  343.    }
  344.    fadeIn(duration_bar,fadeRate);
  345.    fadeIn(progress_bar,fadeRate);
  346.    fadeIn(time_slider,fadeRate);
  347.    setTimeout(function()
  348.    {
  349.       duration_text_holder._alpha = 100;
  350.    }
  351.    ,fadeRate);
  352.    fadeIn(volume_btn,fadeRate);
  353.    if(!is_muted)
  354.    {
  355.       fadeIn(volume_on_btn,fadeRate);
  356.    }
  357.    else
  358.    {
  359.       volume_on_btn._alpha = 0;
  360.    }
  361.    if(Stage.displayState == "fullScreen")
  362.    {
  363.       fadeIn(fullIn,fadeRate);
  364.       fullOut._alpha = 0;
  365.    }
  366.    else
  367.    {
  368.       fullIn._alpha = 0;
  369.       fadeIn(fullOut,fadeRate);
  370.    }
  371. }
  372. function fn_controls_hidden(fadeRate)
  373. {
  374.    controls_visible = false;
  375.    fadeRate = fadeRate || 100;
  376.    fadeOut(controls_bg,fadeRate);
  377.    fadeOut(play_btn,fadeRate);
  378.    fadeOut(pause_btn,fadeRate);
  379.    fadeOut(duration_bar,fadeRate);
  380.    fadeOut(progress_bar,fadeRate);
  381.    fadeOut(time_slider,fadeRate);
  382.    setTimeout(function()
  383.    {
  384.       duration_text_holder._alpha = 0;
  385.    }
  386.    ,fadeRate);
  387.    fadeOut(duration_text,fadeRate);
  388.    fadeOut(volume_btn,fadeRate);
  389.    fadeOut(volume_on_btn,fadeRate);
  390.    fadeOut(fullIn,fadeRate);
  391.    fadeOut(fullOut,fadeRate);
  392. }
  393. function fn_play()
  394. {
  395.    onPlayedChecked = false;
  396.    if(!isStoped && stream.bytesLoaded && video_position != video_duration)
  397.    {
  398.       stream.pause();
  399.    }
  400.    else
  401.    {
  402.       if(isStoped)
  403.       {
  404.          init_vars();
  405.          connect();
  406.       }
  407.       stream.play(_root.src);
  408.    }
  409.    is_playing = true;
  410.    isStoped = false;
  411.    if(controls_visible)
  412.    {
  413.       fn_controls_hidden(10);
  414.       fn_controls_visible(40);
  415.    }
  416.    else
  417.    {
  418.       fn_controls_visible(10);
  419.       fn_controls_hidden(40);
  420.    }
  421.    rightClick.customItems.splice(0,1,cmi_pause);
  422. }
  423. function fn_pause()
  424. {
  425.    is_playing = false;
  426.    stream.pause();
  427.    video_position = stream.time;
  428.    fn_controls_visible();
  429.    rightClick.customItems.splice(0,1,cmi_play);
  430. }
  431. function fn_mute()
  432. {
  433.    is_muted = true;
  434.    audio.setVolume(0);
  435.    fn_controls_visible();
  436.    rightClick.customItems.splice(1,1,cmi_unmute);
  437. }
  438. function fn_unmute()
  439. {
  440.    is_muted = false;
  441.    audio.setVolume(100);
  442.    fn_controls_visible();
  443.    rightClick.customItems.splice(1,1,cmi_mute);
  444. }
  445. function fn_showcontrols()
  446. {
  447.    rightClick.customItems.splice(2,1,cmi_hidecontrols);
  448.    controls_locked = false;
  449.    fn_controls_visible();
  450. }
  451. function fn_hidecontrols()
  452. {
  453.    rightClick.customItems.splice(2,1,cmi_showcontrols);
  454.    fn_controls_hidden();
  455.    controls_locked = true;
  456. }
  457. function fn_fullscreen()
  458. {
  459.    Stage.displayState = "fullScreen";
  460. }
  461. function fn_fullscreen_off()
  462. {
  463.    Stage.displayState = "normal";
  464. }
  465. function display_init()
  466. {
  467.    fn_draw_controls();
  468.    fn_controls_visible();
  469.    fn_resize_poster();
  470.    fn_resize_video();
  471. }
  472. function onPlayed()
  473. {
  474.    if(onPlayedChecked)
  475.    {
  476.       return undefined;
  477.    }
  478.    if(video_duration != undefined && stream.time + 0.4 >= video_duration)
  479.    {
  480.       onPlayedChecked = true;
  481.       is_playing = false;
  482.       isStoped = true;
  483.       setTimeout(function()
  484.       {
  485.          if(loop)
  486.          {
  487.             fn_play();
  488.          }
  489.          else
  490.          {
  491.             video.clear();
  492.             if(posterOnEnd)
  493.             {
  494.                fadeIn(poster_canvas,30);
  495.             }
  496.          }
  497.       }
  498.       ,200);
  499.    }
  500. }
  501. function jsInAs()
  502. {
  503.    fn_play();
  504. }
  505. Stage.align = "LT";
  506. Stage.scaleMode = "noScale";
  507. var connect;
  508. var stream;
  509. var video;
  510. var audio;
  511. var poster_trueWidth;
  512. var poster_trueHeight;
  513. var video_trueWidth;
  514. var video_trueHeight;
  515. var video_position;
  516. var video_percent;
  517. var video_duration;
  518. var is_playing = false;
  519. var is_muted = false;
  520. var is_seeking = false;
  521. var first_hover = false;
  522. var posterOnEnd = _root.posterOnEnd == "true";
  523. var fullScreenEnabled = _root.fullScreenEnabled == "true";
  524. var loop = _root.loop == "true";
  525. var autoplay = _root.autoplay == "true";
  526. var controls_locked = _root.controls == "false";
  527. var controls_visible = _root.controls == "true";
  528. var controls_hover_timeout = 192;
  529. var controls_override = false;
  530. var duration_text_format;
  531. var duration_minutes = "0";
  532. var duration_seconds = "00";
  533. var fullscreen = new Object();
  534. var keyboard = new Object();
  535. var BTN_FULL_W = !fullScreenEnabled ? 0 : 24;
  536. var BTN_FULL_H = 22;
  537. fullIn._visible = fullOut._visible = false;
  538. init_vars();
  539. this.createEmptyMovieClip("poster_canvas",0);
  540. var poster_mclListener = new Object();
  541. poster_mclListener.onLoadInit = function(target_mc)
  542. {
  543.    poster_trueWidth = !_root.width ? poster_canvas._width || Stage.width : _root.width;
  544.    poster_trueHeight = !_root.height ? poster_canvas._height || Stage.height : _root.height;
  545.    fn_resize_poster();
  546. };
  547. var poster_mcl = new MovieClipLoader();
  548. poster_mcl.addListener(poster_mclListener);
  549. poster_mcl.loadClip(_root.poster,poster_canvas);
  550. this.createEmptyMovieClip("video_canvas",300);
  551. connect();
  552. var isStoped = false;
  553. Stage.addListener(fullscreen);
  554. fullscreen.onFullScreen = function()
  555. {
  556.    if(Stage.displayState == "normal")
  557.    {
  558.       controls_override = false;
  559.       _root.menu = rightClick;
  560.    }
  561.    if(Stage.displayState == "fullScreen")
  562.    {
  563.       controls_override = true;
  564.       _root.menu = rightClickBlank;
  565.    }
  566.    fn_controls_visible();
  567.    display_init();
  568.    controls_hover_timeout = 480;
  569. };
  570. Key.addListener(keyboard);
  571. keyboard.onKeyDown = function()
  572. {
  573.    if(Key.isDown(32))
  574.    {
  575.       if(!is_playing)
  576.       {
  577.          fn_play();
  578.       }
  579.       else
  580.       {
  581.          fn_pause();
  582.       }
  583.    }
  584.    if(Key.isDown(17) && Key.isDown(37))
  585.    {
  586.       stream.seek(Math.max(0,stream.time - stream.duration / 10));
  587.       controls_hover_timeout = 288;
  588.    }
  589.    else if(Key.isDown(17) && Key.isDown(39))
  590.    {
  591.       stream.seek(Math.min(video_duration,stream.time + stream.duration / 10));
  592.       controls_hover_timeout = 288;
  593.    }
  594.    else if(Key.isDown(17) && Key.isDown(38))
  595.    {
  596.       if(is_muted)
  597.       {
  598.          fn_unmute();
  599.       }
  600.       controls_hover_timeout = 288;
  601.    }
  602.    else if(Key.isDown(17) && Key.isDown(40))
  603.    {
  604.       if(!is_muted)
  605.       {
  606.          fn_mute();
  607.       }
  608.       controls_hover_timeout = 288;
  609.    }
  610.    else if(Key.isDown(37))
  611.    {
  612.       stream.seek(Math.max(0,stream.time - 15));
  613.       controls_hover_timeout = 288;
  614.    }
  615.    else if(Key.isDown(39))
  616.    {
  617.       stream.seek(Math.min(video_duration,stream.time + 15));
  618.       controls_hover_timeout = 288;
  619.    }
  620. };
  621. var rightClick = new ContextMenu();
  622. rightClick.hideBuiltInItems();
  623. var rightClickBlank = new ContextMenu();
  624. rightClickBlank.hideBuiltInItems();
  625. var cmi_play = new ContextMenuItem("&Play┬á",fn_play);
  626. var cmi_pause = new ContextMenuItem("&Pause┬á",fn_pause);
  627. var cmi_mute = new ContextMenuItem("&Mute┬á",fn_mute);
  628. var cmi_unmute = new ContextMenuItem("Un&mute┬á",fn_unmute);
  629. var cmi_hidecontrols = new ContextMenuItem("Hide &Controls┬á",fn_hidecontrols);
  630. var cmi_showcontrols = new ContextMenuItem("Show &Controls┬á",fn_showcontrols);
  631. var cmi_fullscreen = !fullScreenEnabled ? null : new ContextMenuItem("&Full Screen┬á",fn_fullscreen);
  632. var onPlayedChecked = false;
  633. var checkId = setInterval(function()
  634. {
  635.    if(stream)
  636.    {
  637.       if(stream.bytesLoaded && stream.bytesTotal)
  638.       {
  639.          video_percent = stream.bytesLoaded / stream.bytesTotal * 100;
  640.       }
  641.       video_position = stream.time;
  642.       onPlayed();
  643.    }
  644.    if(controls_visible && controls_hover_timeout <= 0 && first_hover)
  645.    {
  646.       fn_controls_hidden(15);
  647.    }
  648.    else if(controls_visible)
  649.    {
  650.       controls_hover_timeout--;
  651.    }
  652.    fn_time();
  653.    fn_progress();
  654. }
  655. ,9);
  656. setTimeout(function()
  657. {
  658.    display_init();
  659.    duration_text_holder._visible = false;
  660.    fn_controls_hidden(10);
  661.    setTimeout(function()
  662.    {
  663.       duration_text_holder._visible = true;
  664.       fullIn._visible = fullOut._visible = fullScreenEnabled;
  665.    }
  666.    ,350);
  667.    setTimeout(function()
  668.    {
  669.       if(autoplay)
  670.       {
  671.          fn_play();
  672.       }
  673.    }
  674.    ,100);
  675. }
  676. ,100);
  677. if(controls_locked)
  678. {
  679.    rightClick.customItems.push(cmi_play,cmi_mute,cmi_showcontrols,cmi_fullscreen);
  680. }
  681. else
  682. {
  683.    rightClick.customItems.push(cmi_play,cmi_mute,cmi_hidecontrols,cmi_fullscreen);
  684. }
  685. _root.menu = rightClick;
  686. ExternalInterface.addCallback("jsToAs",this,jsInAs);
  687.